package com.ithong.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ithong.drug.entity.Saleinfo;
import com.ithong.drug.mapper.SaleinfoMapper;
import com.ithong.drug.service.SaleinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

import java.util.List;

@Service
public class SaleinfoServiceImpl extends ServiceImpl<SaleinfoMapper, Saleinfo> implements SaleinfoService {

    @Autowired
    private SaleinfoMapper saleinfoMapper;

    @Override
    public IPage<Saleinfo> selectsaleinfoPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Saleinfo> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(param)){
            wrapper.like("dname",param);
        }
        Page<Saleinfo> page = new Page<>(pageNum,pageSize);
        return saleinfoMapper.selectPage(page,wrapper);
    }

    @Override
    public int addsaleinfo(Saleinfo saleinfo) {
        return saleinfoMapper.insert(saleinfo);
    }

    @Override
    public int editsaleinfo(Saleinfo saleinfo) {
        return saleinfoMapper.updateById(saleinfo);
    }

    @Override
    public Saleinfo querysaleinfoById(Integer id) {
        return saleinfoMapper.selectById(id);
    }

    @Override
    public int delsaleinfo(Integer id) {
        return saleinfoMapper.deleteById(id);
    }

    @Override
    public List<Saleinfo> querysaleinfoList() {
        return saleinfoMapper.selectList(null);
    }
}
